package com.kc.web.controller.business;

import com.kc.business.domain.BizArtOrder;
import com.kc.business.service.IBizArtOrderService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import com.kc.common.utils.DictUtils;
import com.kc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/6
 */
@RestController
@RequestMapping("/business/artOrder")
public class BizArtOrderController extends BaseController {
    @Autowired
    private IBizArtOrderService artOrderService;

    /**
     * 艺创订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:artOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizArtOrder artOrder) {
        startPage();
        List<BizArtOrder> list = artOrderService.getList(artOrder);
        for (BizArtOrder order : list) {
            order.setCategoryLable(DictUtils.getDictLabel("art_category", order.getCategory()));
            order.setColorLable(DictUtils.getDictLabel("art_color", order.getColor()));
            order.setMaterialLable(DictUtils.getDictLabel("art_material", order.getMaterial()));
            order.setTechniqueLable(DictUtils.getDictLabel("art_technique", order.getTechnique()));
            order.setOpusUseLable(DictUtils.getDictLabel("art_use", order.getOpusUse()));
            order.setOrnamentationLable(DictUtils.getDictLabel("art_ornamentation", order.getOrnamentation()));
            order.setShapeLable(DictUtils.getDictLabel("art_shape", order.getShape()));
            order.setValueOrientationLable(DictUtils.getDictLabel("art_orientation", order.getValueOrientation()));
            //字符串转景点类型数组
            order.setImgs(StringUtils.split(order.getDetailsImg(), ","));
        }
        return getDataTable(list);
    }

    /**
     * 艺创订单审核
     */
    @PreAuthorize("@ss.hasPermi('business:artOrder:edit')")
    @Log(title = "艺创订单审核", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody @Validated BizArtOrder bizShopEnterForm) {
        return toAjax(artOrderService.edit(bizShopEnterForm));
    }
}
